// generating config files for a logical node
// Created: Apr. 13, 2023 by SUN Yazhou, asia.rabbit@163.com

#ifndef LN_h
#define LN_h

#include <fstream>
#include <string>
#include <vector>
#include "types.h"
#include <map>

using std::ofstream;
using std::string;
using std::vector;
using std::map;

class Port;

class LN{
public:
  // np: number of ports
  LN(int lnid, CMD_TYPE cmd, CRATE_TYPE ct, STREAM_TYPE stream = STREAM_OTHER,
    const string &opt = "");
  virtual ~LN();

  // make connections //
  LN &operator>>(LN &ln); // this -> ln

  const char *IP() const{ return fIP.c_str(); }
  void SetIP(const string &ip){ fIP = ip; }
  void AddPort(Port *p);
  void SetStreamType(STREAM_TYPE type){ fStreamType = type; }
  void Check(); // make sure the ln port is legal

  STREAM_TYPE StreamType() const{ return fStreamType; }
  CRATE_TYPE CrateType() const{ return fCrateType; }

  friend ofstream &operator<<(ofstream &fout, LN &ln);

protected:
  int fLnId;
  CMD_TYPE fCmd;
  STREAM_TYPE fStreamType;
  CRATE_TYPE fCrateType; // the type of crate that this logic node belongs to
  string fOption;
  string fIP; // IP of the crate containing this LN
  vector<Port *> fPortVec;

  static const map<CMD_TYPE, const char *> kCmd_string;
  static const map<STREAM_TYPE, const char *> kStream_string;
};

#endif
